#!/bin/env python
#coding:utf-8
__author__ = 'mason'

import sys
# 导入django Model
import platform
if platform.system() == "Linux":
    sys.path.append("/usr/local/webserver/learn_django")
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'learn_django.settings'
import django
django.setup()
from grafanaCallBack.models import BusinessGroup, TeamUser, PackageName

aTeamUser = [
    {'chinese_name': '梅岩松', 'english_name':'plum', 'email':'plum@yunlai.cn', 'phone_num':'15989523303', 'is_leader':'1', 'is_disable':'0'},
    {'chinese_name': '邓林相', 'english_name':'linx', 'email':'linx@yunlai.cn', 'phone_num':'15364155278', 'is_leader':'0', 'is_disable':'0'},
    ]

nginxApplication = (
    '/APP/web/logs/nginx_log/tqhdstatic.yunlai.cn/tqhdstatic.yunlai.cn.log',
    '/APP/web/logs/nginx_log/emall.yunlai.cn/emall.yunlai.cn.log',
    '/APP/web/logs/nginx_log/mp.yunlai.cn/mp.yunlai.cn.log',
    '/APP/web/logs/nginx_log/cpstatic.yunlai.cn/cpstatic.yunlai.cn.log',
    '/APP/web/logs/nginx_log/im.yunlai.cn/im.yunlai.cn.log',
    '/APP/web/logs/nginx_log/emallstatic.yunlai.cn/emallstatic.yunlai.cn.log',
    '/APP/web/logs/nginx_log/tqhd.yunlai.cn/tqhd.yunlai.cn.log',
    '/APP/web/logs/nginx_log/yyyhd.yunlai.cn/yyyhd.yunlai.cn.log',
    '/APP/web/logs/nginx_log/yqyl.yunlai.cn/yqyl.yunlai.cn.log',
    '/APP/web/logs/nginx_log/ptstatic.yunlai.cn/ptstatic.yunlai.cn.log',
    '/APP/web/logs/nginx_log/cp.yunlai.cn/cp.yunlai.cn.log',
    '/APP/web/logs/nginx_log/boss.yunlai.cn/boss.yunlai.cn.log',
    '/APP/web/logs/nginx_log/pt.yunlai.cn/pt.yunlai.cn.log',
    '/APP/web/logs/nginx_log/my.yunlai.cn/my.yunlai.cn.log',
    '/APP/web/logs/nginx_log/pay.yunlai.cn/pay.yunlai.cn.log',
    '/APP/web/logs/nginx_log/ztxcx.yunlai.cn/ztxcx.yunlai.cn.log',
    '/APP/web/logs/nginx_log/payapi.yunlai.cn/payapi.yunlai.cn.log',
    '/APP/web/logs/nginx_log/cjdslog.yunlai.cn/cjdslog.yunlai.cn.log',
    '/APP/web/logs/nginx_log/gglhd.yunlai.cn/gglhd.yunlai.cn.log',
    '/APP/web/logs/nginx_log/cz.yunlai.cn/cz.yunlai.cn.log',
    '/APP/web/logs/nginx_log/yy.yunlai.cn/yy.yunlai.cn.log',
    '/APP/web/logs/nginx_log/cyzhd.yunlai.cn/cyzhd.yunlai.cn.log',
)

aTeamApplication = (
    "/APP/web/logs/marketing-bespeak-web/log.log",
    "/APP/web/logs/boss-web/log.log",
    "/APP/web/logs/cjds-groupbuy-web/log.log",
    "/APP/web/logs/precision-marketing-web/log.log",
    "/APP/web/logs/cjds-scanqrpay-web/log.log",
    "/APP/web/logs/boss-service-exec/log.log",
    "/APP/web/logs/cjds-scanqrpay-service/log.log",
    "/APP/web/logs/marketing-invite-web/log.log",
    "/APP/web/logs/cjds-couponbuy-service/log.log",
    "/APP/web/logs/marketing-group-coupon-web/log.log",
    "/APP/web/logs/marketing-rpc-provider-exec/master/log.log",
    "/APP/web/logs/marketing-rpc-provider-exec/log.log",
    "/APP/web/logs/groupCoupon-rpc-provider-exec/log.log",
    "/APP/web/logs/marketing-rpc-provider-exec02/log.log",
    "/APP/web/logs/marketing-couponbuy-web/log.log",
    "/APP/web/logs/marketing-scratch-card-web/log.log",
    "/APP/web/logs/marketing-shake-web/log.log",
    "/APP/web/logs/marketing-web-exec/log.log",
    "/APP/web/logs/boss-rpc/log.log",
    "/APP/web/logs/groupCoupon-rpc-provider-exec02/log.log",
    "/APP/web/logs/marketing-face-web/log.log",
    "/APP/web/logs/cjds-special-getway/log.log",
)

bTeamApplication = (    #共11个应用
    "/APP/web/logs/cjds-coupon-service/log.log",
    "/APP/web/logs/cjds-user-service/log.log",
    "/APP/web/logs/cjds-point-service/log.log",
    "/APP/web/logs/stored-value-rpc-exec/log.log",
    "/APP/web/logs/stored-value-web-exec/log.log",
    "/APP/web/logs/payment-rpc-provider-exec/info.log",
    "/APP/web/logs/payment-web-pay-exec/info.log",
    #公共应用
    "/APP/web/logs/cjds-rpc-provider/log.log",
    "/APP/web/logs/cjds-web-mp/log.log",
    "/APP/web/logs/cjds-jobs/log.log",
    "/APP/web/logs/cjds-job-base/log.log",
)

cTeamApplication = (    #共14个应用
    "/APP/web/logs/cjds-shoppingguide-service/log.log",
    "/APP/web/logs/cjds-shoppingguide-gateway/log.log",
    "/APP/web/logs/cjds-authority-service/log.log",
    "/APP/web/logs/wechat-callback-gateway/log.log",
    "/APP/web/logs/wechat-gateway/log.log",
    "/APP/web/logs/wechat-web-auth-exec/log.log",
    "/APP/web/logs/wechat-rpc-provider-exec/log.log",
    "/APP/web/logs/cjds-jobs-accesstoken/log.log",
    "/APP/web/logs/cjds-im-gateway/log.log",
    "/APP/web/logs/cjds-im-service/log.log",
    "/APP/web/logs/cjds-im-thirdparty-service/log.log",
    "/APP/web/logs/cjds-redpack/log.log",
    "/APP/web/logs/cjds-shared-performance-service/log.log",
    # 公共应用
    "/APP/web/logs/cjds-web/log.log",
)

dTeamApplication = (    #共8个应用
    "/APP/web/logs/emall-item-gateway/info.log",
    "/APP/web/logs/emall-item-service-exec/info.log",
    "/APP/web/logs/emall-service-exec/info.log",
    "/APP/web/logs/emall-web-toB-exec/info.log",
    "/APP/web/logs/emall-web-toC-exec/info.log",
    "/APP/web/logs/emall-sku-service-exec/info.log",
    "/APP/web/logs/cjds-oms-service-exec/info.log",
    "/APP/web/logs/cjds-oms-gateway/info.log",
)

def businessInit():
    BusinessGroup.objects.create(chinese_name='运维',
                                 english_name = 'YunWeiTeam_devops',
                                 desc='运维职能	',
                                 rank=0)
    BusinessGroup.objects.create(chinese_name='A组_营销活动',
                                 english_name='ATeam_marketing',
                                 desc='各种营销活动玩法',
                                 rank=1)
    BusinessGroup.objects.create(chinese_name='B组_基础平台	',
                                 english_name='BTeam_base',
                                 desc='基础平台',
                                 rank=2)
    BusinessGroup.objects.create(chinese_name='C组_终端业务',
                                 english_name='CTeam_terminal',
                                 desc='企业微信、IM、导购等PC端业务',
                                 rank=3)
    BusinessGroup.objects.create(chinese_name='D组_货架',
                                 english_name='DTeam_emall',
                                 desc='微信商城',
                                 rank=4)
    # BusinessGroup.objects.create(chinese_name='E组_数据中心',
    #                              english_name='ETeam_datacenter',
    #                              desc='各种数据(商品数据、订单数据、会员数据等)分析',
    #                              rank=5)
    # BusinessGroup.objects.create(chinese_name='F组_开放平台',
    #                              english_name='FTeam_open',
    #                              desc='对外能力开放，以及与企业对接数据同步等业务',
    #                              rank=6)

def userInit():
    TeamUser.objects.update_or_create(chinese_name = u'',english_name = u'', email = u'', phone_num = u''
    )

#setp 1、新建nginx应用，并关联业务组
def nginxApp():
    for index, value in enumerate(nginxApplication):
        print (index,'===>',value)
        packageObj = PackageName.objects.create(name=value,rank = index)
        packageObj.business_group.add(BusinessGroup.objects.get(english_name='YunWeiTeam_devops'))

#setp 2、新建A组应用，并关联业务组
def aTeamApp():
    for index, value in enumerate(aTeamApplication):
        print (index,'===>',value)
        packageObj = PackageName.objects.create(name=value,\
                                                rank = index + 100,
         )
        packageObj.business_group.add(BusinessGroup.objects.get(english_name='ATeam_marketing'))

#setp 3、新建B组应用，并关联业务组
def bTeamApp():
    for index, value in enumerate(bTeamApplication):
        print (index,'===>',value)
        packageObj = PackageName.objects.create(name=value,\
                                                rank = index + 200,
         )
        packageObj.business_group.add(BusinessGroup.objects.get(english_name='BTeam_base'))

#setp 4、新建C组应用，并关联业务组
def cTeamApp():
    for index, value in enumerate(cTeamApplication):
        print (index,'===>',value)
        packageObj = PackageName.objects.create(name=value,\
                                                rank = index + 300,
         )
        packageObj.business_group.add(BusinessGroup.objects.get(english_name='CTeam_terminal'))

#setp 5、新建D组应用，并关联业务组
def dTeamApp():
    for index, value in enumerate(dTeamApplication):
        print (index,'===>',value)
        packageObj = PackageName.objects.create(name=value,\
                                                rank = index + 400,
         )
        packageObj.business_group.add(BusinessGroup.objects.get(english_name='DTeam_emall'))

if __name__ == '__main__':
    #businessInit()
    # nginxApp()
    # aTeamApp()
    # bTeamApp()
    # cTeamApp()
    # dTeamApp()
    pass
